<template>
  <div class="app-container">
    <el-card>
      <el-button
        type="primary"
        size="mini"
        icon="el-icon-plus"
        @click="handleAdd"
      >新建流程</el-button>
      <el-button
        type="primary"
        size="mini"
        icon="el-icon-upload"
      >导入流程</el-button>
      <el-table :data="list">
        <el-table-column label="ID" prop="id" />
        <el-table-column label="模型名称" prop="name" />
        <el-table-column label="模型KEY" prop="processDefinitionKey" />
        <el-table-column label="激活状态" prop="suspensionState">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.suspensionState"
              active-color="#13ce66"
              inactive-color="#ff4949"
            />
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="createTime" />
        <el-table-column label="部署时间" prop="createTime" />
        <el-table-column label="操作" width="400">
          <template slot-scope="scope">
            <el-button type="text">修改流程</el-button>
            <el-button
              type="text"
              @click="handleUpdateWorkflow(scope.row.deploymentId)"
            >设计流程</el-button>
            <el-button type="text">部署流程</el-button>
            <el-button type="text">删除流程</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog :visible.sync="addLoading" title="新建流程" width="400px">
      <el-form :model="form">
        <el-form-item label="模型名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入模型名称" />
        </el-form-item>
        <el-form-item label="模型KEY" prop="processDefinitionKey">
          <el-input
            v-model="form.processDefinitionKey"
            placeholder="请输入模型名称"
          />
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getWorkflow } from '@/api/workflow'
export default {
  name: 'Workflow',
  data() {
    return {
      addLoading: false,
      list: [],
      form: {},
      total: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getWorkflow().then((response) => {
        this.list = response.data.list
        this.total = response.data.total
      })
    },
    handleAdd() {
      this.addLoading = true
    },
    handleUpdateWorkflow(deploymentId) {
      this.$router.push({
        name: 'Bpmn',
        params: { deploymentId: deploymentId }
      })
    }
  }
}
</script>

<style>
</style>
